//判断条件 1设为推荐 2 取消推荐 3 删除

import { ElMessage, ElMessageBox } from "element-plus";

interface SwitchSortModel {
  code: number;
  message: string;
  data: number;
}

export default function MultiSelChange(
  arr: number[],
  str: number,
  reqAPI: (arr: number[], str: number) => PRES<SwitchSortModel>,
  newAPI: (arr: number[]) => PRES<SwitchSortModel>,
  queryList: () => void
) {
  if (arr.length === 0) {
    ElMessage.warning("请选择一条记录");
    return;
  }
  ElMessageBox.confirm(
    str === 3 ? "是否要删除该推荐?" : "是否要修改推荐状态?",
    "提示",
    {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }
  )
    .then(() => {
      if (arr.length !== 0 && str !== 3) {
        reqAPI(arr, str).then((res) => {
          if (res.code === 200) {
            ElMessage.success(" 修改成功");
            queryList();
          }
        });
      } else if (arr.length !== 0 && str == 3) {
        newAPI(arr).then((res) => {
          if (res.code === 200) {
            // console.log(1);
            ElMessage.success(" 删除成功");
            queryList();
          }
        });
      }
    })
    .catch(() => {});
}
